package com.lanou3g.code0510;

import org.apache.commons.io.IOUtils;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;

/*
可以通过注解的形式
来配置servlet的名字和路径
这种写法 就不需要去web.xml 中注册了
效果和写在web.xml中是一致的
 */
@WebServlet(name = "HWServlet",urlPatterns ="/error404")
public class HWServlet extends HttpServlet {


    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        ServletContext app = getServletContext();


        InputStream is = app.getResourceAsStream("Error404.html");

        String html = IOUtils.toString(is);
        response.getWriter().println(html);

        is.close();



    }
}
